#include <pwd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <libxml/parser.h>
#include <grp.h>
#include <libxml/xmlmemory.h>
#include "../include/ohsm.h"
#include "ohsm_u.h"

long long 
validate_id_long(xmlChar *s)
{
	char *t = NULL;
	long long retval;

	retval = strtoll ((char *)s, &t,10);
	if ( retval < 0)
		return -1;
	if (*t == '\0')
		return retval;	
	return -1;
}

int 
validate_id(xmlChar *s)
{
	char *t = NULL;
	unsigned int retval;

	if (!s)
		return -1;
	retval = strtol( (char *)s, &t,10);	
	
	if (*t == '\0')
		return retval;	
	return -1;
}

int 
validate_key(xmlChar *s)
{
	long int retval;

	if (!s)
		return -1;
	retval = validate_id(s);
	if (retval < 0)
		return -1;
	return retval;
}

int
validate_user(uid_t user)
{
  struct passwd *temp_user = NULL;

  temp_user = getpwuid(user);
  if (temp_user)
	return -1;
  return 0;
}

int
validate_group(gid_t group)
{
  struct group *temp_group = NULL;

  temp_group = getgrgid(group);
  if (!temp_group)
	return -1;
  return 0;
}
